package com.jianzh5.entity;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * TRole entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "t_role", catalog = "")
@DynamicInsert(true)
@DynamicUpdate(true)
public class TRole implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer id;
	private String rolename;
	private String remark;
	private Integer seq;
	private Set<TAdmin> TAdmins = new HashSet<TAdmin>(0);
	private Set<TResource> TResources = new HashSet<TResource>(0);

	// Constructors

	/** default constructor */
	public TRole() {
	}

	/** full constructor */
	public TRole(String rolename, String remark, Integer seq,
			Set<TAdmin> TAdmins, Set<TResource> TResources) {
		this.rolename = rolename;
		this.remark = remark;
		this.seq = seq;
		this.TAdmins = TAdmins;
		this.TResources = TResources;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "rolename", length = 50)
	public String getRolename() {
		return this.rolename;
	}

	public void setRolename(String rolename) {
		this.rolename = rolename;
	}

	@Column(name = "remark", length = 100)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name = "seq")
	public Integer getSeq() {
		return this.seq;
	}

	public void setSeq(Integer seq) {
		this.seq = seq;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "t_user_role", catalog = "", joinColumns = { @JoinColumn(name = "roleid", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "userid", nullable = false, updatable = false) })
	public Set<TAdmin> getTAdmins() {
		return this.TAdmins;
	}

	public void setTAdmins(Set<TAdmin> TAdmins) {
		this.TAdmins = TAdmins;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "t_role_resource", catalog = "", joinColumns = { @JoinColumn(name = "roleid", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "resourceid", nullable = false, updatable = false) })
	@OrderBy("seq asc")
	public Set<TResource> getTResources() {
		return this.TResources;
	}

	public void setTResources(Set<TResource> TResources) {
		this.TResources = TResources;
	}

}